#ifndef _CKDATABASE_H_
#define _CKDATABASE_H_



#include <map>
#include <vector>
#include "mysql/mysql.h"

namespace K_Engine
{
	class CKDBSelectResult
	{
		friend class CKDatabase;
	private:
		CKDBSelectResult(MYSQL_RES* _res);
		~CKDBSelectResult();
		std::map<std::string, int> listname;
		std::map<int, std::vector<std::string>*> listvalue;
		int nResultLength;
		int nListLength;
		
	public:
		const std::vector<std::string>* GetLine(const int i);
		const std::string& GetValue(const int index, std::string strListName);
		int nGetResultLength() const;
		int nGetResultListLength() const;
	};
	
	class CKDatabase
	{
	private:
		std::string m_dbhost;
		std::string m_user;
		std::string m_passwork;
		std::string m_dbname;
		bool bConnection;
		MYSQL m_conn;
		
	public:
		CKDatabase();
		~CKDatabase();
		void SetHost(std::string _host);
		void SetUserPasswork(std::string _user, std::string _passwork);
		void SetDBname(std::string _dbname);
	
	public:
		bool connectDB();
		bool Query(std::string strsql);
		CKDBSelectResult* Select(std::string strsql);
		void FreeCKDBSR(CKDBSelectResult* free);
	};
}

#endif // ! _CKDATABASE_H_
